﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TomShane.Neoforce.Controls;
using Microsoft.Xna.Framework;

namespace MapEditor
{
    class MainWindowMapEditor
    {
        private Manager m;
        private GraphicsDeviceManager graphics;
        private Window w;
        private MainMenu mainMenu;
        WindowMapEditSize mapedit;

        public bool IsVisible { get { return w.Visible; } set { w.Visible = value; } }
        public Rectangle MainRect { get { return new Rectangle(w.Left, w.Top, w.Width, w.Height); } }
        public Rectangle EditSizeRect { get { return new Rectangle(mapedit.w.Left, mapedit.w.Top, mapedit.w.Width, mapedit.w.Height); } }
        public bool IsEditVisible { get { return mapedit.w.Visible; } set { mapedit.w.Visible = value; } }

        public WindowMapEditSize MapEdit { get { return mapedit; } }

        public Window Window { get { return w; } }

        public bool LockDrawing { get; set; }

        public MainWindowMapEditor(Manager m, GraphicsDeviceManager g)
        {

            

            this.m = m;
            graphics = g;
            w = new Window(m);
            w.Init();
            w.Text = "Main Window";
            w.Width = 400;
            w.Height = 800;
            w.Top = 5;
            w.Left = g.PreferredBackBufferWidth - w.Width - 5 ;
            m.Add(w);

            //MainMenu
            mainMenu = new MainMenu(m);
            mainMenu.Init();
            mainMenu.StayOnTop = true;
            mainMenu.Anchor = Anchors.Top | Anchors.Left;
            mainMenu.ControlRect = new Rectangle(0, 0, w.Width - 20, 20);
            mainMenu.TextColor = Color.Black;

            MenuItem file = new MenuItem("File", true);
            MenuItem open = new MenuItem("Open", false);
            MenuItem save = new MenuItem("Save", false);
            MenuItem exit = new MenuItem("Exit", false);

            file.Items.AddRange(new MenuItem[] { open, save, exit });
            mainMenu.Items.AddRange(new MenuItem[] { file });
            //w.Add(mainMenu);

            MenuItem edit = new MenuItem("Edit", true);
            MenuItem editSize = new MenuItem("Edit Size", false);

            editSize.Click += new TomShane.Neoforce.Controls.EventHandler(click_edit);


            /* AJOUT DE FONCTIONS POUR LOCK LE DESSIN */

            w.ResizeBegin += new TomShane.Neoforce.Controls.EventHandler(w_ResizeBegin);
            w.ResizeEnd += new TomShane.Neoforce.Controls.EventHandler(w_ResizeEnd);
            w.MoveBegin += new TomShane.Neoforce.Controls.EventHandler(w_MoveBegin);
            w.MoveEnd += new TomShane.Neoforce.Controls.EventHandler(w_MoveEnd);
            LockDrawing = false;


            mapedit = new WindowMapEditSize(m, graphics);
            mapedit.w.Visible = false;

            mapedit.w.ResizeBegin += new TomShane.Neoforce.Controls.EventHandler(w_ResizeBegin);
            mapedit.w.ResizeEnd += new TomShane.Neoforce.Controls.EventHandler(w_ResizeEnd);
            mapedit.w.MoveBegin += new TomShane.Neoforce.Controls.EventHandler(w_MoveBegin);
            mapedit.w.MoveEnd += new TomShane.Neoforce.Controls.EventHandler(w_MoveEnd);

            edit.Items.AddRange(new MenuItem[] { editSize });
            mainMenu.Items.AddRange(new MenuItem[] { edit });
            w.Add(mainMenu);
        }

        private void click_edit(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            mapedit.w.Visible = true;
        }


        private void w_ResizeBegin(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            LockDrawing = true;
        }

        public void w_ResizeEnd(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            LockDrawing = false;
        }

        public void w_MoveBegin(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            LockDrawing = true;
        }

        public void w_MoveEnd(object sender, TomShane.Neoforce.Controls.EventArgs e)
        {
            LockDrawing = false;
        }

    }
}
